package com.shwread.android.qysw.step.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shwread.android.qysw.step.dto.HMRank;
import com.shwread.android.qysw.step.view.RectImageView;
import com.shwread.android.qysw.tools.Screen;
import com.shwread.android.qysw10000204.R;
import com.squareup.picasso.Picasso;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by Fantasy on 16/4/1.
 */

public class RankAdapter extends LoadMoreListViewAdapter {

    Context mContext;

    public RankAdapter(Context context) {
        this.mContext = context;
    }


    @Override
    public RecyclerView.ViewHolder subOnCreateViewHolder(ViewGroup parent, int viewType) {
        View rootView = LayoutInflater.from(parent.getContext()).inflate(R.layout.healthy_other_user_grade_item, null);
        rootView.setLayoutParams(new RecyclerView.LayoutParams(Screen.getScreenWidth(), ViewGroup.LayoutParams.WRAP_CONTENT));
        RecyclerView.ViewHolder itemViewHolder = new RankViewHolder(rootView);
        return itemViewHolder;
    }

    @Override
    public void subOnBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        RankViewHolder rankViewHolder = (RankViewHolder) holder;
        HMRank hmRank = (HMRank) total_data_list.get(position);
        rankViewHolder.numberText.setText(hmRank.getSort() + "");
        rankViewHolder.nameText.setText(hmRank.getNickName());
        rankViewHolder.stepCountText.setText(hmRank.getStep() + "");
        if (!TextUtils.isEmpty(hmRank.getUserHead())) {
            Picasso.with(mContext).load(hmRank.getUserHead()).into(rankViewHolder.headIconImg);
        }else {
            rankViewHolder.headIconImg.setImageResource(R.drawable.user_head);
        }
    }

    static class RankViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.number_text)
        TextView numberText;
        @InjectView(R.id.head_icon_img)
        RectImageView headIconImg;
        @InjectView(R.id.name_text)
        TextView nameText;
        @InjectView(R.id.step_count_text)
        TextView stepCountText;

        RankViewHolder(View view) {
            super(view);
            ButterKnife.inject(this, itemView);
        }
    }
}
